﻿Module modScr
    Public Declare Auto Function SystemParametersInfo Lib "user32" (ByVal uAction As Integer, ByVal uParam As Integer, ByRef pvParam As Integer, ByVal fuWinIni As Integer) As Boolean
    Public Const SPI_SCREENSAVERRUNNING = 97&
    Public Const frmedge As Integer = 4
    Public nMouseMoves&
    Dim sStartType


    Public Sub Main(ByVal args As String())
        Dim Inst As Boolean = False


        If args.Length > 0 Then
            sStartType = args(0).ToLower.Trim().Substring(0, 2)

            If sStartType = "" Then
                'This will occur when a user right-clicks the .SCR
                'file and chooses "configure"
                sStartType = "/c"
            End If

            ' Determine whether the screen saver should show user-definable options.
            If sStartType = "/c" Then
                Dim usercnfg As New frmcnfg
                usercnfg.ShowDialog()

                ' Exit the application.
                Exit Sub
            End If

            ' Determine whether the screen saver should just execute.
            If sStartType = "/s" Then
                'Check for previous instance.
                Inst = PrevInstance()
                If Not (Inst) Then
                    ' Create a Screen Saver form and display the form.
                    Dim scrsvr As New frmscr
                    scrsvr.ShowDialog()
                Else
                    'If a previous instance exists, exit the application.
                    Exit Sub
                End If
            End If
        End If
    End Sub


    Function PrevInstance() As Boolean
        If UBound(Diagnostics.Process.GetProcessesByName(Diagnostics.Process.GetCurrentProcess.ProcessName)) > 0 Then
            Return True
        Else
            Return False
        End If
    End Function
    Public Function GetScaleWidth(ByVal frm As Form) As Integer

        Dim ctl As Control
        Dim w As Integer = frm.ClientSize.Width

        For Each ctl In frm.Controls
            With ctl
                If .GetContainerControl() Is frm Then
                    If .Dock = DockStyle.Left Or .Dock = DockStyle.Right Then
                        w = w - .Size.Width
                    End If
                End If
            End With
        Next
        GetScaleWidth = w - frmedge
    End Function

    Public Function SustituyeHTML(ByVal texto As String) As String
        texto.Replace("&lt;", "<")
        texto.Replace("&gt;", ">")
        Return texto
    End Function

End Module
